from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-07 14:05:43.972196
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 07, May, 2021
Time: 14:05:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0620
Nobs: 284.000 HQIC: -48.7548
Log likelihood: 3452.20 FPE: 4.21545e-22
AIC: -49.2184 Det(Omega_mle): 3.08733e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.398800 0.116876 3.412 0.001
L1.Burgenland 0.071545 0.059174 1.209 0.227
L1.Kärnten -0.224706 0.052622 -4.270 0.000
L1.Niederösterreich 0.108745 0.126731 0.858 0.391
L1.Oberösterreich 0.216152 0.122863 1.759 0.079
L1.Salzburg 0.277601 0.067459 4.115 0.000
L1.Steiermark 0.108170 0.086261 1.254 0.210
L1.Tirol 0.121870 0.059723 2.041 0.041
L1.Vorarlberg -0.031554 0.054875 -0.575 0.565
L1.Wien -0.038477 0.110318 -0.349 0.727
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.426162 0.134807 3.161 0.002
L1.Burgenland 0.003467 0.068253 0.051 0.959
L1.Kärnten 0.328585 0.060696 5.414 0.000
L1.Niederösterreich 0.121453 0.146175 0.831 0.406
L1.Oberösterreich -0.071527 0.141713 -0.505 0.614
L1.Salzburg 0.229357 0.077808 2.948 0.003
L1.Steiermark 0.088476 0.099495 0.889 0.374
L1.Tirol 0.137344 0.068886 1.994 0.046
L1.Vorarlberg 0.152129 0.063294 2.404 0.016
L1.Wien -0.406461 0.127243 -3.194 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.249806 0.059375 4.207 0.000
L1.Burgenland 0.105145 0.030062 3.498 0.000
L1.Kärnten -0.014212 0.026733 -0.532 0.595
L1.Niederösterreich 0.095179 0.064382 1.478 0.139
L1.Oberösterreich 0.280441 0.062417 4.493 0.000
L1.Salzburg 0.023041 0.034270 0.672 0.501
L1.Steiermark -0.002402 0.043822 -0.055 0.956
L1.Tirol 0.068762 0.030341 2.266 0.023
L1.Vorarlberg 0.076300 0.027878 2.737 0.006
L1.Wien 0.119580 0.056044 2.134 0.033
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206436 0.056694 3.641 0.000
L1.Burgenland 0.028425 0.028704 0.990 0.322
L1.Kärnten 0.009369 0.025526 0.367 0.714
L1.Niederösterreich 0.057088 0.061475 0.929 0.353
L1.Oberösterreich 0.393154 0.059598 6.597 0.000
L1.Salzburg 0.081885 0.032723 2.502 0.012
L1.Steiermark 0.131433 0.041843 3.141 0.002
L1.Tirol 0.051511 0.028970 1.778 0.075
L1.Vorarlberg 0.081633 0.026619 3.067 0.002
L1.Wien -0.041741 0.053513 -0.780 0.435
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.445295 0.111478 3.994 0.000
L1.Burgenland 0.103102 0.056442 1.827 0.068
L1.Kärnten 0.010022 0.050192 0.200 0.842
L1.Niederösterreich 0.032969 0.120879 0.273 0.785
L1.Oberösterreich 0.114008 0.117189 0.973 0.331
L1.Salzburg 0.060916 0.064343 0.947 0.344
L1.Steiermark 0.063358 0.082277 0.770 0.441
L1.Tirol 0.200692 0.056965 3.523 0.000
L1.Vorarlberg 0.037857 0.052341 0.723 0.470
L1.Wien -0.063023 0.105223 -0.599 0.549
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213035 0.087430 2.437 0.015
L1.Burgenland -0.011624 0.044266 -0.263 0.793
L1.Kärnten -0.006237 0.039365 -0.158 0.874
L1.Niederösterreich -0.014885 0.094803 -0.157 0.875
L1.Oberösterreich 0.416741 0.091909 4.534 0.000
L1.Salzburg 0.011973 0.050463 0.237 0.812
L1.Steiermark -0.027741 0.064528 -0.430 0.667
L1.Tirol 0.161510 0.044676 3.615 0.000
L1.Vorarlberg 0.058367 0.041050 1.422 0.155
L1.Wien 0.204671 0.082524 2.480 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199574 0.106709 1.870 0.061
L1.Burgenland 0.022672 0.054027 0.420 0.675
L1.Kärnten -0.070982 0.048045 -1.477 0.140
L1.Niederösterreich -0.040576 0.115707 -0.351 0.726
L1.Oberösterreich 0.007714 0.112175 0.069 0.945
L1.Salzburg 0.089636 0.061590 1.455 0.146
L1.Steiermark 0.317092 0.078757 4.026 0.000
L1.Tirol 0.460281 0.054528 8.441 0.000
L1.Vorarlberg 0.148013 0.050101 2.954 0.003
L1.Wien -0.131240 0.100721 -1.303 0.193
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205088 0.126815 1.617 0.106
L1.Burgenland 0.040388 0.064207 0.629 0.529
L1.Kärnten -0.074306 0.057097 -1.301 0.193
L1.Niederösterreich 0.116917 0.137509 0.850 0.395
L1.Oberösterreich 0.013020 0.133312 0.098 0.922
L1.Salzburg 0.193390 0.073196 2.642 0.008
L1.Steiermark 0.130530 0.093597 1.395 0.163
L1.Tirol 0.054744 0.064802 0.845 0.398
L1.Vorarlberg 0.106907 0.059542 1.796 0.073
L1.Wien 0.221245 0.119700 1.848 0.065
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.503425 0.070636 7.127 0.000
L1.Burgenland -0.013312 0.035763 -0.372 0.710
L1.Kärnten -0.017391 0.031803 -0.547 0.584
L1.Niederösterreich 0.110341 0.076592 1.441 0.150
L1.Oberösterreich 0.302184 0.074254 4.070 0.000
L1.Salzburg 0.023558 0.040770 0.578 0.563
L1.Steiermark -0.047324 0.052133 -0.908 0.364
L1.Tirol 0.082092 0.036095 2.274 0.023
L1.Vorarlberg 0.103581 0.033165 3.123 0.002
L1.Wien -0.044479 0.066672 -0.667 0.505
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.161355 0.094442 0.169332 0.221101 0.078023 0.089160 0.001152 0.164570
Kärnten 0.161355 1.000000 0.056809 0.212461 0.185901 -0.066184 0.177737 0.021374 0.307507
Niederösterreich 0.094442 0.056809 1.000000 0.244681 0.097511 0.317407 0.151105 0.025069 0.321672
Oberösterreich 0.169332 0.212461 0.244681 1.000000 0.301211 0.260533 0.103868 0.061528 0.143490
Salzburg 0.221101 0.185901 0.097511 0.301211 1.000000 0.150313 0.073132 0.091433 0.028772
Steiermark 0.078023 -0.066184 0.317407 0.260533 0.150313 1.000000 0.095120 0.100380 -0.099532
Tirol 0.089160 0.177737 0.151105 0.103868 0.073132 0.095120 1.000000 0.152949 0.160907
Vorarlberg 0.001152 0.021374 0.025069 0.061528 0.091433 0.100380 0.152949 1.000000 -0.009737
Wien 0.164570 0.307507 0.321672 0.143490 0.028772 -0.099532 0.160907 -0.009737 1.000000